package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.CheckBackboneEquipmentAttrHandler;
import com.iwhalecloud.bss.kite.cucc.service.util.ProdCateUtil;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
@AttrHandler(CheckBackboneEquipmentAttrHandler.class)
public class CheckBackboneEquipmentAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Autowired
    private IOperateSceneInstService operateSceneInstService;

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        // 互联网
        if (KiteStringUtils.equals(inst.getSpecId(), ProdCateUtil.getSingleProdId(ProdCateUtil.DIA_CODE))) {
            List<KiteAttr> list = new ArrayList<>();
            list.add(inst.getAttr("200001371"));//接入省网/城域网自治域号
            list.add(inst.getAttr("200001370"));//接入省网/城域网名称
            list.add(inst.getAttr("200001552"));//接入设备名称
            list.add(inst.getAttr("200001393"));//接入端口号
            if (KiteStringUtils.equals(attr.getValue(), "1_0000106")) { // 是
                list.stream().forEach(kiteAttr -> kiteAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D));
            } else if (KiteStringUtils.equals(attr.getValue(), "1_0000107")) { //否
                list.stream().forEach(kiteAttr -> kiteAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E));
            }
            operateSceneInstService.setAttrs(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), list);
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
